<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        // 去重
        // function unique(arr) {
        //     return [...new Set(arr)]
        // }
        function sortByNameAndScore() {
            let data = [
                { name: '李四', subject: '数学', score: 91 },
                { name: '张三', subject: '语文', score: 92 },
                { name: '张三', subject: '外语', score: 88 },
                { name: '王五', subject: '数学', score: 89 },
                { name: '李四', subject: '语文', score: 93 },
                { name: '李四', subject: '外语', score: 89 },
                { name: '王五', subject: '语文', score: 91 },
                { name: '张三', subject: '数学', score: 90 },
                { name: '王五', subject: '外语', score: 87 },
            ]
            let newData = []
            let nameData = []
            let subData = []
            data.map(item => {
                if (nameData.indexOf(item.name) == -1) {
                    nameData.push(item.name)
                }
                if (subData.indexOf(item.subject) == -1) {
                    subData.push(item.subject)
                }
            })
            nameData.map(name => {
                subData.map(subject => {
                    console.log(name, 'name')
                    console.log(subject, 'subject')
                    data.map(item => {
                        if (item.name == name && item.subject == subject) {
                            newData.push(item)
                            return
                        }
                    })

                })
            })
            console.log(newData, 'newData') //结果
        }
    
    </script>
</head>

<body>
    <button onclick="sortByNameAndScore()">按钮</button>

</body>

</html>